function D_unmerge = shell_unmerge_fringe(D, N_st, ...
    Delta_xi, s1_predicted, s1_predicted_y, s1_predicted_y_c, s1_predicted_y_m,...
    r2_mm, p2_mm, delta_p_mm, s2_mkt_mm, claims2_mm, pr_s_mm)

% data on major dummy, # of mkts, # of fringes in a given mkt
D_major = D.major;
if sum(D_major==0) ~= N_st
    disp('ERROR: sum(D_major==0) ~= N_st')
end
D_nF = D.n_insurers(D_major==0); % N_st x 1, contains # of fringes in a given mkt

%% unmerge market shares
arg_share=1;

% observed 1st-stage mkt shares
D_unmerge.s1 = unmerge_fringe(D.s1, D_major, arg_share, D_nF, N_st); % NN x 1

% predicted 1st-stage mkt shares
D_unmerge.s1_predicted = unmerge_fringe(s1_predicted, D_major, arg_share, D_nF, N_st); % NN x 1
D_unmerge.s1_predicted_y = unmerge_fringe(s1_predicted_y', D_major, arg_share, D_nF, N_st)'; % N_y x NN
D_unmerge.s1_predicted_y_c = unmerge_fringe(s1_predicted_y_c', D_major, arg_share, D_nF, N_st)'; % N_y x NN
D_unmerge.s1_predicted_y_m = unmerge_fringe(s1_predicted_y_m', D_major, arg_share, D_nF, N_st)'; % N_y x NN

% predicted 2nd-stage mkt shares
D_unmerge.s2_mkt = unmerge_fringe(s2_mkt_mm, D_major, arg_share, D_nF, N_st); % NN x K*M

%% unmerge other variables
arg_share=0;

% variables below are state-contingent
D_unmerge.r2 = unmerge_fringe(r2_mm, D_major, arg_share, D_nF, N_st); % NN x K*M
D_unmerge.p2 = unmerge_fringe(p2_mm, D_major, arg_share, D_nF, N_st); % NN x K*M
D_unmerge.delta_p = unmerge_fringe(delta_p_mm, D_major, arg_share, D_nF, N_st); % NN x K*M
D_unmerge.claims2 = unmerge_fringe(claims2_mm, D_major, arg_share, D_nF, N_st); % NN x K*M
D_unmerge.pr_s = unmerge_fringe(pr_s_mm, D_major, arg_share, D_nF, N_st); % NN x K*M

% others
D_unmerge.Delta_xi = unmerge_fringe(Delta_xi, D_major, arg_share, D_nF, N_st); % NN x 1
D_unmerge.mkt = unmerge_fringe(D.mkt, D_major, arg_share, D_nF, N_st); % NN x 1
D_unmerge.state = unmerge_fringe(D.state, D_major, arg_share, D_nF, N_st); % NN x 1
D_unmerge.year = unmerge_fringe(D.year, D_major, arg_share, D_nF, N_st); % NN x 1
D_unmerge.naic = unmerge_fringe(D.naic, D_major, arg_share, D_nF, N_st); % NN x 1
D_unmerge.major = unmerge_fringe(D.major, D_major, arg_share, D_nF, N_st); % NN x 1
D_unmerge.id_is = unmerge_fringe(D.id_is, D_major, arg_share, D_nF, N_st); % NN x 1
D_unmerge.id_ps = unmerge_fringe(D.id_ps, D_major, arg_share, D_nF, N_st); % NN x 1
D_unmerge.p1 = unmerge_fringe(D.p1, D_major, arg_share, D_nF, N_st); % NN x 1
D_unmerge.n_insurers = unmerge_fringe(D.n_insurers, D_major, arg_share, D_nF, N_st); % NN x 1
D_unmerge.reg_year = unmerge_fringe(D.reg_year, D_major, arg_share, D_nF, N_st); % NN x 1
D_unmerge.id_ist = unmerge_fringe(D.id_ist, D_major, arg_share, D_nF, N_st); % NN x 1
D_unmerge.in_regression = unmerge_fringe(D.in_regression, D_major, arg_share, D_nF, N_st); % NN x 1

D_unmerge.pr_k = unmerge_fringe(D.pr_s, D_major, arg_share, D_nF, N_st);  % NN x K
D_unmerge.pr_mm = unmerge_fringe(D.pr_mm, D_major, arg_share, D_nF, N_st); % NN x M
